package com.cn.jinl.controller;

import com.cn.jinl.api.IProcureStorageOutService;
import com.cn.jinl.domain.ProcureStorageOut;
import com.cn.jinl.domain.ProcureStorageOutHis;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/procureStorageOut")
public class ProcureStorageOutController {

    @Autowired
    private IProcureStorageOutService procureStorageOutService;

    @RequestMapping("/getProcureStorageList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProcureStorageOut>> getProcureStorageList(@PathVariable(value = "frontToken",required = true) String frontToken, @RequestBody QueryForm queryForm) throws Exception{
        JsonResponse<List<ProcureStorageOut>> response = new JsonResponse<>();
        List<ProcureStorageOut> procureStorageOuts = procureStorageOutService.getProcureStorageOutList(queryForm);
        response.setResult(procureStorageOuts);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/selectProcureStorageOutMXList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProcureStorageOut>> selectProcureStorageOutMXList(@PathVariable(value = "frontToken",required = true) String frontToken, @RequestBody QueryForm queryForm) throws Exception{
        JsonResponse<List<ProcureStorageOut>> response = new JsonResponse<>();
        List<ProcureStorageOut> procureStorageOuts = procureStorageOutService.selectProcureStorageOutMXList(queryForm);
        response.setResult(procureStorageOuts);
        response.setSuccess(true);
        return response;
    }

    @RequestMapping("/getProcureStorageOutHisById/{frontToken}")
    @ResponseBody
    public JsonResponse<List<ProcureStorageOutHis>> getProcureStorageOutHisById(@PathVariable(value = "frontToken",required = true) String frontToken, String id) throws Exception{
        JsonResponse<List<ProcureStorageOutHis>> response = new JsonResponse<>();
        List<ProcureStorageOutHis> procureStorageOuts = procureStorageOutService.getProcureStorageOutHisById(id);
        response.setResult(procureStorageOuts);
        response.setSuccess(true);
        return response;
    }


    @RequestMapping("/addProcureStorageOut/{frontToken}")
    @ResponseBody
    public JsonResponse<String> addProcureStorageOut(@RequestBody ProcureStorageOut procureStorageOut, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = procureStorageOutService.addProcureStorageOut(procureStorageOut);
        return CommonUtil.getResponseData(response,result);
    }

}
